package com.ruoyi.sycs.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import com.ruoyi.report_tg.domain.bo.TgsybgBaDetailBo;
import com.ruoyi.report_tg.domain.vo.TgsybgBaDetailVo;
import com.ruoyi.sycs.domain.BiQualification;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaCheckLogin;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.sycs.domain.vo.BiQualificationVo;
import com.ruoyi.sycs.domain.bo.BiQualificationBo;
import com.ruoyi.sycs.service.IBiQualificationService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 检测项目图鉴
 *
 * @author zyb
 * @date 2024-04-08
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/sycs/biQualification")
public class BiQualificationController extends BaseController {

    private final IBiQualificationService iBiQualificationService;


    /**
     * 计算检测项目结果
     */
    @SaCheckLogin
//    @RepeatSubmit(interval = 0)
    @PostMapping("/compute")
    public R<List<TgsybgBaDetailVo>> compute(@RequestBody List<TgsybgBaDetailVo> voList) {
        return R.ok(iBiQualificationService.compute(voList));
    }

    /**
     * 查询检测项目图鉴列表
     */
    @SaCheckLogin
    @GetMapping("/list")
    public TableDataInfo<BiQualificationVo> list(BiQualificationBo bo, PageQuery pageQuery) {
        return iBiQualificationService.queryPageList(bo, pageQuery);
    }

    /**
     * 查询检测项目图鉴列表
     */
    @SaCheckLogin
    @GetMapping("/biList")
    public R<List<BiQualification>> biList(BiQualificationBo bo) {
        return R.ok(iBiQualificationService.biList(bo));
    }

    /**
     * 导出检测项目图鉴列表
     */
    @SaCheckLogin
    @Log(title = "检测项目图鉴", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(BiQualificationBo bo, HttpServletResponse response) {
        List<BiQualificationVo> list = iBiQualificationService.queryList(bo);
        ExcelUtil.exportExcel(list, "检测项目图鉴", BiQualificationVo.class, response);
    }

    /**
     * 获取检测项目图鉴详细信息
     *
     * @param qualId 主键
     */
    @SaCheckLogin
    @GetMapping("/{qualId}")
    public R<BiQualificationVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long qualId) {
        return R.ok(iBiQualificationService.queryById(qualId));
    }

    /**
     * 新增检测项目图鉴
     */
    @SaCheckLogin
    @Log(title = "检测项目图鉴", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody BiQualificationBo bo) {
        return toAjax(iBiQualificationService.insertByBo(bo));
    }

    /**
     * 修改检测项目图鉴
     */
    @SaCheckLogin
    @Log(title = "检测项目图鉴", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody BiQualificationBo bo) {
        return toAjax(iBiQualificationService.updateByBo(bo));
    }

    /**
     * 删除检测项目图鉴
     *
     * @param qualIds 主键串
     */
    @SaCheckLogin
    @Log(title = "检测项目图鉴", businessType = BusinessType.DELETE)
    @DeleteMapping("/{qualIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] qualIds) {
        return toAjax(iBiQualificationService.deleteWithValidByIds(Arrays.asList(qualIds), true));
    }
}
